package java_learn.java_jinjie.DataStructure;

import java.util.*;

/**
 * @Author: 李浩然
 * @Date: 2020/12/5 11:20 下午
 * 斗地主 综合案例-有序版本
 * 具体规则：
 * <p>
 * 1. 组装54张扑克牌将
 * 2. 54张牌顺序打乱
 * 3. 三个玩家参与游戏，三人交替摸牌，每人17张牌，最后三张留作底牌。
 * 4. 查看三人各自手中的牌（按照牌的大小排序）、底牌
 * <p>
 * > 规则：手中扑克牌从大到小的摆放顺序：大王,小王,2,A,K,Q,J,10,9,8,7,6,5,4,3
 */
public class Doudizhu {
    public static void main(String[] args) {
        HashMap<Integer, String> pokermap = new HashMap<>();
        ArrayList<String> colors = new ArrayList<>();
        ArrayList<String> numbers = new ArrayList<>();
        Collections.addAll(colors, "♠️", "♥️", "♦️", "♣️");
        Collections.addAll(numbers, "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3");
        int count = 1;
        pokermap.put(count++, "大王");
        pokermap.put(count++, "小王");
        for (String number : numbers) {
            for (String color : colors) {
                pokermap.put(count++, color + number);
            }
        }
        Set<Integer> numberSet = pokermap.keySet();
        ArrayList<Integer> numberList = new ArrayList<>();
        numberList.addAll(numberSet);
        Collections.shuffle(numberList);
        ArrayList<Integer> nop1 = new ArrayList<>();
        ArrayList<Integer> nop2 = new ArrayList<>();
        ArrayList<Integer> nop3 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();

        for (int i = 0; i < numberList.size(); i++) {
            Integer num = numberList.get(i);
            if (i >= 51) {
                diPai.add(num);
            } else {
                if (i % 3 == 0) {
                    nop1.add(num);
                } else if (i % 3 == 1) {
                    nop2.add(num);
                } else {
                    nop3.add(num);
                }
            }
        }
        Collections.sort(nop1);
        Collections.sort(nop2);
        Collections.sort(nop3);
        Collections.sort(diPai);
        ArrayList<String> player1 = new ArrayList<String>();
        ArrayList<String> player2 = new ArrayList<String>();
        ArrayList<String> player3 = new ArrayList<String>();
        ArrayList<String> dipai = new ArrayList<String>();
        for (Integer i : nop1) {
            // 4.4 根据编号找到 牌面 pokerMap
            String card = pokermap.get(i);
            // 添加到对应的 牌面集合中
            player1.add(card);
        }

        for (Integer i : nop2) {
            String card = pokermap.get(i);
            player2.add(card);
        }
        for (Integer i : nop3) {
            String card = pokermap.get(i);
            player3.add(card);
        }
        for (Integer i : diPai) {
            String card = pokermap.get(i);
            dipai.add(card);
        }

        //4.5 查看
        System.out.println("令狐冲：" + player1);
        System.out.println("石破天：" + player2);
        System.out.println("鸠摩智：" + player3);
        System.out.println("底牌：" + dipai);
    }
}
